package com.best.onegous.details;


import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.json.JSONException;
import org.json.JSONObject;

import com.best.onegous.BaseActivity;
import com.best.onegous.R;
import com.best.onegous.agreement.ApiInterface;
import com.best.onegous.http.BusinessResponse;
import com.best.onegous.http.HttpClients;
import com.loopj.android.http.RequestParams;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.widget.ProgressBar;
import android.widget.TextView;

public class XiJieWebView  extends BaseActivity implements OnClickListener,BusinessResponse{
	private WebView webView;
	private ProgressBar progressBar;
	private String codeGoodsID;
	private TextView titleview;
	private HttpClients httpclient;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setThem(R.layout.activity_xijie);
		Intent intent = getIntent();
		codeGoodsID = intent.getStringExtra("codeGoodsID");
		
		findViewById(R.id.back).setOnClickListener(this);
		webView = (WebView) findViewById(R.id.webView);
        progressBar = (ProgressBar) findViewById(R.id.progressBar1);
		
		findViewById(R.id.back).setOnClickListener(this);
		 webView.getSettings().setJavaScriptEnabled(true);
	        webView.getSettings().setSupportZoom(true); 
	        webView.getSettings().setBuiltInZoomControls(true);
	        webView.getSettings().setUseWideViewPort(true);
	        webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
	        webView.getSettings().setLoadWithOverviewMode(true);
	        
	      
	        webView.setWebViewClient(new WebViewClient() {
	            public boolean shouldOverrideUrlLoading(WebView view, String url) {
	                view.loadUrl(url);
	                return true;
	            }
	        });
	        webView.setWebChromeClient(new WebChromeClient() {
	 
	            public void onProgressChanged(WebView view, int progress) {
	 
	                if (progress == 100) {
	 
	 
	                    progressBar.setVisibility(View.GONE);
	                }
	 
	            }
	 
	        });
	        httpclient = new HttpClients(this);
			httpclient.addResponseListener(this);
			  RequestParams params = new RequestParams();
			  params.add("sid",codeGoodsID);
			httpclient.httpclient(ApiInterface.GENGDUOSHANGPINXIJIE, params, true);
	}

    private String fmtString(String str){
    String notice = "";
    try{
    notice = URLEncoder.encode(str, "utf-8");
    }catch(UnsupportedEncodingException ex){
    }
    return notice;
    }

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back:
			finish();
			break;

		}
	}
	@Override
	public void OnMessageResponse(String url, JSONObject jo)
			throws JSONException {
		
		if (url.equals(ApiInterface.GENGDUOSHANGPINXIJIE)) {
			if (null != jo) {
				   webView.loadData(jo.getString("data"), "text/html", "utf-8");
				     
			}
		}
		
	}  
}
